<script type="text/javascript" src="/ueditor/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="/ueditor/ueditor.all.min.js"></script>
<!-- 编辑器公式插件 -->
<script type="text/javascript" charset="utf-8" src="/ueditor/kityformula-plugin/addKityFormulaDialog.js"></script>
<script type="text/javascript" charset="utf-8" src="/ueditor/kityformula-plugin/getKfContent.js"></script>
<script type="text/javascript" charset="utf-8" src="/ueditor/kityformula-plugin/defaultFilterFix.js"></script>
<div class="span10" id="datacontent">
<style>
    .up_file {  position:relative;  text-decoration:none; text-indent:0;}
    .up_file input { position:absolute; font-size:100px; right:0; top:0; opacity:0; width: 100%;}
    .up_file:hover { background:#ffa55d;color:#fff; text-decoration:none;}
</style>
    <ul class="breadcrumb">
        <li><a href="/exercise/index/index">剑雅真题</a> <span class="divider">/</span></li>
        <li><a href="/exercise/listening/index">听力练习</a> <span class="divider">/</span></li>
        <li class="active">添加题目</li>
    </ul>
    <form action="/exercise/listening/add" method="post" class="form-horizontal">
        <fieldset>
            <div class="control-group">
                <label for="area" class="control-label">主分类：</label>
                <div class="controls">
                    <select name="cate_id" id="">
                        <?php foreach ($option['cate'] as $k => $v): ?>
                            <option value="<?php echo $v['cate_id']?>" <?php echo $cate_id==$v['cate_id']?'selected':''?>><?php echo $v['name']?></option>

                        <?php endforeach ?>
                    </select>
                </div>
            </div>
            <div class="control-group">
                <label for="area" class="control-label">名称：</label>
                <div class="controls">
                    <input type="text" name="name" value="">
                </div>
            </div>
            <div class="control-group">
                <label for="area" class="control-label">标题：</label>
                <div class="controls">
                    <input type="text" value="" name="title">
                </div>
            </div>
            <div class="control-group">
                <label for="area" class="control-label">标题图片：</label>
                <div class="controls">
                    <input type="text" value="" class="title_image" name="title_image">
                    <a href="#" class="btn btn-info" onclick="upImage3()">上传文件</a>
                </div>
            </div>

            <div class="control-group">
                <label for="area" class="control-label">题目图片：</label>
                <div class="controls">
                    <input type="text" value="" class="image" name="image">
                    <a href="#" class="btn btn-info" onclick="upImage4()">上传文件</a>
                </div>
            </div>
            <div class="control-group">
                <label for="area" class="control-label">浏览量：</label>
                <div class="controls">
                    <input type="text" value="" name="viewCount">
                </div>
            </div>
            <div class="control-group">
                <label for="area" class="control-label">选择音频：</label>
                <div class="controls">
                    <a href="#" class="btn btn-info up_file">选择音频<input type="file" /></a>
                    <span class="audioFile"></span>
                </div>
            </div>
            <div class="control-group">
                <label for="area" class="control-label">听力文件：</label>
                <div class="controls">
                    <textarea name="listeningFile" id="listeningFile" style="width: 300px;height: 100px;"></textarea>
                    <a href="#" class="btn btn-info" onclick="upAudio()">上传音频</a>
                </div>
            </div>
            <div class="control-group">
                <label for="area" class="control-label">描述：</label>
                <div class="controls">
                    <textarea id="sss" name="description" style="width: 90%;height: 400px;"></textarea>
                </div>
            </div>
            <div class="control-group">
                <label for="area" class="control-label">文章：</label>
                <div class="controls">
                    <textarea id="sss2" name="article" style="width: 90%;height: 400px;"></textarea>
                </div>
            </div>
            <div class="control-group">
                <label for="area" class="control-label">题型：</label>
                <div class="controls">
                    <select name="type" id="">
                    <?php foreach ($option['type'] as $k => $v): ?>
                            <option value="<?php echo $v['id']?>"><?php echo $v['name']?></option>
                            
                        <?php endforeach ?>
                    </select>
                </div>
            </div>
            <div class="control-group">
                <label for="area" class="control-label">难度：</label>
                <div class="controls">
                    <select name="level" id="">
                    <?php foreach ($option['level'] as $k => $v): ?>
                            <option value="<?php echo $v['id']?>"><?php echo $v['name']?></option>
                            
                        <?php endforeach ?>
                    </select>
                </div>
            </div>
            <div class="control-group">
                <label for="area" class="control-label">话题：</label>
                <div class="controls">
                    <select name="topic" id="">
                    <?php foreach ($option['topic'] as $k => $v): ?>
                            <option value="<?php echo $v['id']?>"><?php echo $v['name']?></option>
                            
                        <?php endforeach ?>
                    </select>
                </div>
            </div>
            <div class="control-group">
                <label for="area" class="control-label">问题类型：</label>
                <div class="controls">
                    <input type="text" value="1" name="questionType">
                </div>
            </div>
            <div class="control-group">
                <label for="area" class="control-label">考点：</label>
                <div class="controls">
                    <input type="text" value="" name="test_site">
                </div>
            </div>
            <div class="control-group">
                <div class="controls">
                    <button class="btn btn-primary" type="submit">提交</button>
                    <input type="hidden" name="id" value=""/>
                </div>
            </div>
        </fieldset>
    </form>
</div>
<script>
    //实例化编辑器
    //描述
    var o_ueditorupload = UE.getEditor('sss',
        {
            autoHeightEnabled:false
        });
    // 文章
    var o_ueditorupload2 = UE.getEditor('sss2',
        {
            autoHeightEnabled:false
        });
    
    
    // 标题图片
    var o_ueditorupload3 = UE.getEditor('j_ueditorupload3',
        {
            autoHeightEnabled:false
        });
    o_ueditorupload3.ready(function ()
    {

        o_ueditorupload3.hide();//隐藏编辑器

        //监听图片上传
        o_ueditorupload3.addListener('beforeInsertImage', function (t,arg)
        {
            $('.title_image').val(arg[0].src);

        });

        /* 文件上传监听
         * 需要在ueditor.all.min.js文件中找到
         * d.execCommand("insertHtml",l)
         * 之后插入d.fireEvent('afterUpfile',b)
         */
        o_ueditorupload3.addListener('afterUpfile', function (t, arg)
        {

        });
    });

    function upImage3()
    {
        var myImage3 = o_ueditorupload3.getDialog("insertimage");
        myImage3.open();
    }

    var o_ueditorupload4 = UE.getEditor('j_ueditorupload4',
        {
            autoHeightEnabled:false
        });
    o_ueditorupload4.ready(function ()
    {

        o_ueditorupload4.hide();//隐藏编辑器

        //监听图片上传
        o_ueditorupload4.addListener('beforeInsertImage', function (t,arg)
        {
            $('.image').val(arg[0].src);

        });

        /* 文件上传监听
         * 需要在ueditor.all.min.js文件中找到
         * d.execCommand("insertHtml",l)
         * 之后插入d.fireEvent('afterUpfile',b)
         */
        o_ueditorupload4.addListener('afterUpfile', function (t, arg)
        {

        });
    });

    function upImage4()
    {
        var myImage4 = o_ueditorupload4.getDialog("insertimage");
        myImage4.open();
    }


    $(".up_file input").change(function(e){
        var fileMsg = e.currentTarget.files;
        if(fileMsg.length==0){
            $(".audioFile").text('');
            return false;
        }
        var fileFullName = fileMsg[0].name;
        //var fileMasterName=fileFullName.substr(0,fileFullName.lastIndexOf("."));
        $(".audioFile").text('已选择文件：'+fileFullName)
    })

    function upAudio() {
        var data = new FormData();
        data.append('file', $('.up_file input').get(0).files[0]);
        $.ajax({
            type: 'POST',
            url: "/cn/api/upload",
            dataType: "json",
            contentType:false,
            processData: false,
            data: data,
            success: function(res) {
                alert(res.message)
                if(res.code == 1||res.code == 2){
                    var files = $.trim($('#listeningFile').val());
                    if(files.indexOf(res.data)==-1){
                        files += '<p>'+res.domain+res.data+'</p>';
                        $('#listeningFile').val(files);
                    }else{
                        alert('听力文件中已存在该文件，请检查')
                    }
                } else {

                }
            },
            error: function(e){
               alert('系统错误，请重试')
            },
        });
    }
</script>
<script type="text/plain" id="sss"></script>
<script type="text/plain" id="sss2"></script>
<script type="text/plain" id="j_ueditorupload3"></script>
<script type="text/plain" id="j_ueditorupload4"></script>